package com.lanou3g.hw0420;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by dllo on 18/4/20.
 */
public class Main {
    public static void main(String[] args) {
        Socket socket=new Socket();
        Scanner scanner=new Scanner(System.in);
        PrintWriter pw=null;

        try {
            socket.connect(new InetSocketAddress("127.0.0.1",2333));
            new ReadThread(socket).start();
            OutputStream os=socket.getOutputStream();
            pw=new PrintWriter(new OutputStreamWriter(os));

            while (true){
                String line=scanner.nextLine();
                pw.println(line);
                pw.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (pw!=null){
                pw.close();
            }
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            scanner.close();
        }

    }
}
